package com.example.demo.service.impl;

import java.util.List;

import com.example.demo.entity.Cart;
import com.example.demo.mapper.CartMapper;
import com.example.demo.service.ICartService;
import com.example.demo.utils.PageResult;
import com.example.demo.utils.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * cartService业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-24
 */
@Service
public class CartServiceImpl implements ICartService
{
    @Autowired
    private CartMapper cartMapper;

    /**
     * 查询cart
     * 
     * @param cartid cart主键
     * @return cart
     */
    @Override
    public Cart selectCartByCartid(Long cartid)
    {
        return cartMapper.selectCartByCartid(cartid);
    }

    /**
     * 查询cart列表
     * 
     * @param cart cart
     * @return cart
     */
    @Override
    public List<Cart> selectCartList(Cart cart)
    {
        return cartMapper.selectCartList(cart);
    }

    @Override
    public PageResult CartGoodsList(Cart cart, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Cart> list = cartMapper.cartGoodsList(cart);
        PageInfo<Cart> pageInfo = new PageInfo<>(list);
        PageResult pageResult = PageUtils.getPageResult(pageInfo);
        return  pageResult;

    }

    /**
     * 新增cart
     * 
     * @param cart cart
     * @return 结果
     */
    @Override
    public int insertCart(Cart cart)
    {
        return cartMapper.insertCart(cart);
    }

    /**
     * 修改cart
     * 
     * @param cart cart
     * @return 结果
     */
    @Override
    public int updateCart(Cart cart)
    {
        return cartMapper.updateCart(cart);
    }

    @Override
    public int updateCartNum(Cart cart) {
        return cartMapper.updateCartNum(cart);
    }

    /**
     * 批量删除cart
     * 
     * @param cartids 需要删除的cart主键
     * @return 结果
     */
    @Override
    public int deleteCartByCartids(Long[] cartids)
    {
        return cartMapper.deleteCartByCartids(cartids);
    }

    /**
     * 删除cart信息
     * 
     * @param cartid cart主键
     * @return 结果
     */
    @Override
    public int deleteCartByCartid(Long cartid)
    {
        return cartMapper.deleteCartByCartid(cartid);
    }
}
